//
//  DYJiudianYuyueCell.swift
//  SheYangBigData
//
//  Created by 宋海胜 on 2021/1/11.
//  Copyright © 2021 叁拾叁. All rights reserved.
//


import UIKit

class DYJiudianYuyueCell: SYBaseCell , UITableViewDelegate, UITableViewDataSource {
    
    var models: [DYZSRoomListModel] = []
    var model: DYZSDetailModel!
    var tableView: UITableView!
    
    var bgView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = UIColor(hex: 0x367FF6)
        v.layer.cornerRadius = 2
        return v
    }()
    
    let nameLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x1E1E1E)
        v.font = 17.autoBoldFontSize()
        v.text = "酒店预订"
        return v
    }()
    
    var sepView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = Constant.bgViewColor
        return v
    }()

    public func configureView(_ model: DYZSDetailModel) {
        self.model = model
        self.models = model.roomList ?? []
        tableView.snp.remakeConstraints { (make) in
            make.top.equalTo(nameLb.snp.bottom).offset(autoWidth(10.0))
            make.left.right.equalToSuperview()
            make.height.equalTo(112.0.autoWidth()*CGFloat(models.count))
            make.bottom.equalToSuperview().offset(-16.autoWidth())
        }
        tableView.reloadData()
    }
    
    override func initViews() {
        
        setTableView()
        contentView.addSubview(nameLb)
        contentView.addSubview(bgView)
        contentView.addSubview(tableView)
        contentView.addSubview(sepView)
        bgView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(16.0.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(14.5))
            make.width.equalTo(4.0.autoWidth())
            make.height.equalTo(15.0.autoWidth())
        }
        nameLb.snp.makeConstraints { (make) in
            make.centerY.equalTo(bgView)
            make.left.equalTo(bgView.snp.right).offset(autoWidth(7.0))
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.height.equalTo(16.0.autoWidth())
        }
        tableView.snp.makeConstraints { (make) in
            make.top.equalTo(nameLb.snp.bottom).offset(autoWidth(10.0))
            make.left.right.equalToSuperview()
            make.height.equalTo(112.0.autoWidth()*0)
            make.bottom.equalToSuperview().offset(-16.autoWidth())
        }
        sepView.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.height.equalTo(10.0.autoWidth())
            make.bottom.equalToSuperview()
        }
    }
    
    func setTableView() {
        
        //创建表格视图
        self.tableView = UITableView(frame: CGRect.zero, style:.plain)
        self.tableView.separatorStyle = .none
        self.tableView.delegate = self
        self.tableView.dataSource = self
//        self.tableView.isScrollEnabled = false
        self.tableView!.register(DYJiudianYuyueSubCell.self, forCellReuseIdentifier: "Cell")
        self.contentView.addSubview(self.tableView!)
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.models.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell: DYJiudianYuyueSubCell? = tableView.dequeueReusableCell(withIdentifier: "Cell") as? DYJiudianYuyueSubCell
        cell?.selectionStyle = .none
        cell?.currentVC = self.currentVC
        cell?.configureView(self.models[indexPath.row])
        return cell!
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let vc = DYZSYuyueViewController(model: self.model, selectIndex: indexPath.row, selectTime: "", endTime: "", dayNum: 1)
        self.currentVC.navigationController?.pushViewController(vc, animated: true)
    }
}

